<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/20
 * Time: 10:30
 */
namespace app\model;

use think\Model;
use think\Db;

class Article extends Model {
    protected $connection = 'database';
    protected $table = 'article';

    public function getList($where, $limit = '') {
        $list = [];
        if (empty($limit)) {
            $res = $this->where($where)->select();
        } else {
            $res = $this->where($where)->limit($limit)->select();
        }
        if (!empty($res)) {
            $list = collection($res)->toArray();
        }
        return $list;
    }

    public function getTotal($where) {
        $total = $this->where($where)->count();
        return empty($total) ? 0 : $total;
    }

    public function getOneInfo($where, $field = '*')
    {
        $list = [];
        $res = $this->field($field)->where($where)->find();
        if (!empty($res)) {
            $list = $res->toArray();
        }
        return $list;
    }

    public function insertData($data)
    {
        $res = $this->insertGetId($data);
        return $res;
    }

    public function updateData($where, $data)
    {
        $res = $this->where($where)->update($data);
        return $res;
    }
}